package com.marquee.customview;

import com.marquee.R;
import com.marquee.R.styleable;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.WindowManager.LayoutParams;
import android.widget.FrameLayout;
import android.widget.TextView;

public class MyTextView extends TextView{

	final String Default_typefaceName ="arita.ttf";
	
	
	Context context;
	

	public MyTextView(Context context) {
		super(context);
		this.context = context;
		setDefault();
	}

	
	public MyTextView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		this.context = context;
		applyTypeface(context, attrs);
	}

	public MyTextView(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.context = context;
		applyTypeface(context, attrs);
	}

	private void applyTypeface(Context context, AttributeSet attrs){
		TypedArray arr = context.obtainStyledAttributes(attrs, R.styleable.MyTextView);
		String typefaceName = arr.getString(R.styleable.MyTextView_typeface);
		Typeface typeface = null;
		try{
			if(typefaceName==null){
				typefaceName = this.Default_typefaceName;
			}
			typeface = Typeface.createFromAsset(context.getAssets(), typefaceName);
			setTypeface(typeface);
		}catch(Exception e){
			e.printStackTrace();
		}	
	}
	
	
	
	public void setFont(String fontName){
		Typeface tf = Typeface.createFromAsset(context.getAssets(), fontName);
		setTypeface(tf);
			
	}
	
	

	private void setDefault(){
		
		
		Typeface tf = Typeface.createFromAsset(context.getAssets(), Default_typefaceName);
		setTypeface(tf);
		FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT,Gravity.CENTER);
		setLayoutParams(params);
		setGravity(Gravity.CENTER);
		setTextColor(Color.BLACK);
		
		
	}
	

}

